//
//  HomeViewController.m
//  AndCampus
//
//  Created by 史宵宵 on 2017/11/6.
//  Copyright © 2017年 史宵宵. All rights reserved.
//

#import "HomeViewController.h"
#import "PYSearchViewController.h"
#import "ExtensionInfo.h"
#import "PopularityViewController.h"
#import "RecommendViewController.h"
#import "NewsViewController.h"
#import "CouponViewController.h"
#import "GasStationListViewController.h"
#import "ActivityDetailViewController.h"
#import "InterestingIslandViewController.h"
#import "YSSearchViewControllerViewController.h"
#import "XinyuInteractionViewController.h"
#import "PopularityInfo.h"
#import "YJLoginViewController.h"
#import "RelaxViewController.h"
#import "ClipBoundsTableViewCell.h"
#import "ClassmateDetailViewController.h"
#import "LiveDetailViewController.h"
#import "ClassRoomDetailViewController.h"
#import "MajorTestViewController.h"

@interface HomeViewController ()<PYSearchViewControllerDelegate>
@property(nonatomic,weak)RKImageBrowser *browserImageView;
@property (nonatomic,strong) NSMutableArray *imageDataArray;
@property (nonatomic,strong) NSMutableArray *extensionArray;
@property (nonatomic,strong) NSMutableArray *popularityArray;

//@property(nonatomic,weak) UIImageView *headimageview;
@end

@implementation HomeViewController
- (NSMutableArray *)imageDataArray{
    if (!_imageDataArray) {
        _imageDataArray = [NSMutableArray array];
    }
    return _imageDataArray;
}
- (NSMutableArray *)extensionArray{
    if (!_extensionArray) {
        _extensionArray = [NSMutableArray array];
    }
    return _extensionArray;
}
- (NSMutableArray *)popularityArray{
    if (!_popularityArray) {
        _popularityArray = [NSMutableArray array];
    }
    return _popularityArray;
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return UIStatusBarStyleLightContent;
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets=NO;
    // Do any additional setup after loading the view.
    
    [self getHomePage];
    [self getHomeExtension];
    if ([[JHUserInfo getUserInfo].role_type isEqualToString:@"1"]) {
        [self creatPopularityList];
    }
    CGRect rect=self.view.bounds;
    rect.size.height-= 49 + 64;
    self.tableView.frame=rect;
    //    self.tableView.contentInset=UIEdgeInsetsMake(kScreenW / 2-20, 0, 0, 0);
    
    UIView *searchView = [[UIView alloc]init];
    searchView.frame = CGRectMake(0, 0, kScreenW - 100, 30);
    searchView.backgroundColor = [UIColor whiteColor];
    searchView.clipsToBounds = YES;
    searchView.layer.cornerRadius = 15;
    searchView.userInteractionEnabled = YES;
    self.navigationItem.titleView = searchView;

    UIImageView *searchImage = [[UIImageView alloc]init];
    searchImage.frame = CGRectMake( 15, 11, 21, 21);
    searchImage.image = [UIImage imageNamed:@"img_search"];
    [searchView addSubview:searchImage];
    
    UIButton *label = [[UIButton alloc]init];
    [label setTitle:@"搜索你想要的" forState:UIControlStateNormal];
    [label setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    label.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    label.titleLabel.font = [UIFont systemFontOfSize:15];
    label.frame = CGRectMake(15, 8, CGRectGetWidth(searchView.frame) - 25 - 22 - 5 - 10 - 21 - 5, 15);
    [label addTarget:self action:@selector(enterSearchView) forControlEvents:UIControlEventTouchDown];
    [searchView addSubview:label];
    
    UIImageView *recordImage = [[UIImageView alloc]init];
    recordImage.frame = CGRectMake( CGRectGetWidth(searchView.frame) - 25 - 22- 5, 11, 19, 22);
    recordImage.image = [UIImage imageNamed:@"icon_voice"];
    [searchView addSubview:recordImage];
    
    UIImageView *scanImage = [[UIImageView alloc]init];
    scanImage.frame = CGRectMake( CGRectGetWidth(searchView.frame) - 25, 11, 20, 20);
    scanImage.image = [UIImage imageNamed:@"icon_scan"];
    [searchView addSubview:scanImage];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(0, 0, 75, 31);
    button.adjustsImageWhenHighlighted = NO;
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [button setImage:[UIImage imageNamed:@"icon_logo"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"icon_logo"] forState:UIControlStateHighlighted];
    button.imageView.contentMode=UIViewContentModeScaleAspectFit;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem rightBarButtonItemWithImage:[UIImage imageNamed:@"bell"] highlighted:[UIImage imageNamed:@"bell"] target:self selector:@selector(publish)];
    [self setupRefresh];
}
/**
 *  集成刷新控件
 */
- (void)setupRefresh
{
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getHomePage];
        if ([[JHUserInfo getUserInfo].role_type isEqualToString:@"1"]) {
            [self creatPopularityList];
        }
        [self getHomeExtension];
    }];
   
}
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 4;
}
#pragma mark - TableViewDelegate
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 3) {
        return self.extensionArray.count;
    }

    if (![[JHUserInfo getUserInfo].role_type isEqualToString:@"1"] && section == 2) {
        return 0;
    }
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
//        static NSString *CellIdentifier = @"Cell";
        ClipBoundsTableViewCell *cell=[ClipBoundsTableViewCell cellWithTableView:tableView];
        
        //加载轮播图
        RKImageBrowser *browserImageView = [[RKImageBrowser alloc] initWithFrame:CGRectMake(0, 0, kScreenW - 20, kScreenW / 2)];
        self.browserImageView = browserImageView;
        self.browserImageView.backgroundColor = [UIColor clearColor];
        if (self.imageDataArray.count > 0) {
            NSMutableArray *imageArray = [[NSMutableArray alloc]init];
            [self.imageDataArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                ExtensionInfo *extensionInfo = obj;
                NSString *imgUrl = [strIsEmpty(extensionInfo.pathUrl)?@"":extensionInfo.pathUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                [imageArray addObject:imgUrl];
            }];
            [self.browserImageView setBrowserWithImagesArray:imageArray];
        }
        __weak typeof(self) unself = self;
        self.browserImageView.didselectRowBlock = ^(NSInteger clickRow) {
            ExtensionInfo *extensionInfo = unself.imageDataArray[clickRow];
            NSString *type = [NSString stringWithFormat:@"%@",extensionInfo.source];
            if ([type isEqualToString:@"1"]) { //1与时资讯
                WebViewController *webView = [[WebViewController alloc]initWithTitle:extensionInfo.title withRequest:[NSString stringWithFormat:@"%@/sys/home/gasStation?fileEntryId=%@",URL_BASE,extensionInfo.path]];
                [unself.navigationController pushViewController:webView animated:YES];
            }else if ([type isEqualToString:@"2"]) { //2外网链接
                WebViewController *webView = [[WebViewController alloc]initWithTitle:extensionInfo.title withRequest:extensionInfo.path];
                [unself.navigationController pushViewController:webView animated:YES];
            }else if ([type isEqualToString:@"3"]) {//课程详情
                if (strIsEmpty([Global getUserTokenInfo])) {
                    [unself login];
                }
                YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
                NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
                [dic setValue:extensionInfo.path forKey:@"courseId"];
                [dic setValue:[Global getUserTokenInfo] forKey:@"token"];
                [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppCourseGetCourseTypeById] andParmas:dic andComplition:^(id response, BOOL isuccess) {
                    if (isuccess) {
                        if ([[NSString stringWithFormat:@"%@",response[@"videoType"]] isEqualToString:@"1"]) { //1直播  2课程
                            LiveDetailViewController *liveDetailVC = [[LiveDetailViewController alloc]init];
                            liveDetailVC.liveDetailId = [NSString stringWithFormat:@"%@",response[@"course_id"]];
                            [unself.navigationController pushViewController:liveDetailVC animated:YES];
                        }else{
                            ClassRoomDetailViewController *classRoomDetailVC = [[ClassRoomDetailViewController alloc]init];
                            classRoomDetailVC.courseId = [NSString stringWithFormat:@"%@",response[@"course_id"]];
                            [unself.navigationController pushViewController:classRoomDetailVC animated:YES];
                        }
                    }
                }];
            }else if ([type isEqualToString:@"5"]) {//活动招募
                if (strIsEmpty([Global getUserTokenInfo])) {
                    [unself login];
                }
                ActivityDetailViewController *activityDetailVC = [[ActivityDetailViewController alloc]init];
                activityDetailVC.activityId = extensionInfo.path;
//                activityDetailVC.activityId = @"77";
                [self.navigationController pushViewController:activityDetailVC animated:YES];
            }else if ([type isEqualToString:@"7"]) { //7学业加油站资讯
                if (strIsEmpty([Global getUserTokenInfo])) {
                    [unself login];
                }
                WebViewController *webView = [[WebViewController alloc]initWithTitle:extensionInfo.title withRequest:[NSString stringWithFormat:@"%@/sys/home/gasStation?fileEntryId=%@&token=%@",URL_BASE,extensionInfo.path,[Global getUserTokenInfo]]];
                [unself.navigationController pushViewController:webView animated:YES];
            }
        
        };
        [cell.contentView addSubview:self.browserImageView];
        return cell;
    }else if (indexPath.section == 1){
//        static NSString *CellIdentifier = @"Cell1";
//        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//
//        if (!cell) {
//            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
//            cell.selectionStyle=UITableViewCellSelectionStyleNone;
//            cell.accessoryType = UITableViewCellAccessoryNone;
//        }
        ClipBoundsTableViewCell *cell=[ClipBoundsTableViewCell cellWithTableView:tableView];
        
        
        NSArray *imageArray = @[@"Home_interaction",@"Home_Evaluation",@"Home_GasStation",@"Home_Relaxation",@"Home_Interesting",@"Home_Teacher"];
        NSArray *textArray = @[@"心语互动",@"专业测评",@"学业加油站",@"放松区",@"趣味岛",@"与时名师"];
        for (int i = 0; i < textArray.count;  i ++) {
            CustomeButton *titleButton=[[CustomeButton alloc]init];
            titleButton.relative = KRelativeAlignmentDown;
//            titleButton.backgroundColor = [UIColor yellowColor];
            //            titleButton.imageView.backgroundColor = [UIColor clearColor];
            titleButton.frame = CGRectMake(30 +((kScreenW - 20) / 3 ) * (i % 3), 10 + (kScreenW / 3 / 2 + 30) * (i / 3), ((kScreenW - 20)) / 3/2 , kScreenW / 3 / 2 + 30);
            titleButton.imageRect = CGRectMake( 0, 5, (kScreenW - 20) / 3 / 2 , (kScreenW - 20) / 3 / 2 - 10);
            titleButton.titleRect = CGRectMake( -30 , CGRectGetMaxY(titleButton.imageRect) + 10, (kScreenW - 20) / 3, 20);
            titleButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
            titleButton.titleLabel.font = [UIFont systemFontOfSize:14];
            titleButton.titleLabel.textAlignment = NSTextAlignmentCenter;
            [titleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [titleButton setTitle:textArray[i] forState:UIControlStateNormal];
            [titleButton setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
            titleButton.tag = 2000 + i;
            [titleButton addTarget:self action:@selector(enterCompany:) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView addSubview:titleButton];
        }
        
        return cell;
    }else if (indexPath.section == 2){
        static NSString *CellIdentifier = @"Cell2";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        
        if (!cell) {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType = UITableViewCellAccessoryNone;
        }
        double imageWidth = 50;
        double margin = (kScreenW - 50 * 3) / 6;
        NSArray *titleArray = @[@"日榜",@"周榜",@"月榜"];
        NSArray *titleColorArray = @[KBACKNAVIGATIONCOLOR,RGBColor(250, 105, 103),RGBColor(112, 145, 251)];
        NSArray *imageBacArray = @[@"day",@"week",@"month"];
        for (int i = 0; i < self.popularityArray.count; i ++) {
            PopularityInfo *popularityInfo = self.popularityArray[i];
            
            UILabel *listLabel = [[UILabel alloc]init];
            listLabel.frame = CGRectMake( margin + (2*margin + imageWidth) * i, 10, imageWidth, 20);
            listLabel.backgroundColor = titleColorArray[i];
            listLabel.text = titleArray[i];
            listLabel.textAlignment = NSTextAlignmentCenter;
            listLabel.textColor = [UIColor whiteColor];
            listLabel.clipsToBounds = YES;
            listLabel.layer.cornerRadius = 10;
            [cell.contentView addSubview:listLabel];
            
            UIImageView *bacIconImage  = [[UIImageView alloc]init];
            bacIconImage.frame = CGRectMake(CGRectGetMinX(listLabel.frame), 35, imageWidth, imageWidth);
            bacIconImage.image = [UIImage imageNamed:imageBacArray[i]];
            [cell.contentView addSubview:bacIconImage];
            
            UIImageView *iconImage  = [[UIImageView alloc]init];
            iconImage.frame = CGRectMake(CGRectGetMinX(listLabel.frame)+9, 46, imageWidth-12, imageWidth-12);
            iconImage.clipsToBounds = YES;
            iconImage.layer.cornerRadius = (imageWidth-12)/2;
            [iconImage sd_setImageWithURL:[NSURL URLWithString:popularityInfo.icon] placeholderImage: KSIDEDEFAULTHEAD];
            iconImage.userInteractionEnabled = YES;
            iconImage.tag = 5000+i;
            [iconImage addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(enterImageView:)]];
            [cell.contentView addSubview:iconImage];
            
            UILabel *nameLabel = [[UILabel alloc]init];
            nameLabel.frame = CGRectMake(CGRectGetMinX(listLabel.frame), CGRectGetMaxY(iconImage.frame) + 5, imageWidth, 20);
            nameLabel.text = popularityInfo.nick_name;
            nameLabel.font = [UIFont systemFontOfSize:14];
            nameLabel.textColor = KTEXTMAINCOLOR;
            nameLabel.textAlignment = NSTextAlignmentCenter;
            nameLabel.adjustsFontSizeToFitWidth = YES;
            [cell.contentView addSubview:nameLabel];
        }
        
        return cell;
    }else {
        static NSString *CellIdentifier = @"Cell3";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        
        if (!cell) {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.accessoryType = UITableViewCellAccessoryNone;
            
            UIImageView *iconImage = [[UIImageView alloc]init];
            iconImage.frame = CGRectMake( 10, 10, 110, 60);
            iconImage.tag = 1000;
            iconImage.clipsToBounds = YES;
            iconImage.layer.cornerRadius = 5;
            [cell.contentView addSubview:iconImage];
            
            UILabel *nameLabel = [[UILabel alloc]init];
            nameLabel.tag = 1001;
            nameLabel.numberOfLines = 2;
            nameLabel.textAlignment = NSTextAlignmentLeft;
            nameLabel.font = [UIFont systemFontOfSize:16];
            nameLabel.textColor = [UIColor blackColor];
            [cell.contentView addSubview:nameLabel];
            
            UILabel *reportLabel = [[UILabel alloc]init];
            reportLabel.tag = 1002;
            reportLabel.textAlignment = NSTextAlignmentLeft;
            reportLabel.font = [UIFont systemFontOfSize:12];
            reportLabel.textColor = [UIColor darkTextColor];
            [cell.contentView addSubview:reportLabel];
            
            UILabel *attentionLabel = [[UILabel alloc]init];
            attentionLabel.tag = 1003;
            attentionLabel.textAlignment = NSTextAlignmentRight;
            attentionLabel.font = [UIFont systemFontOfSize:12];
            attentionLabel.textColor = [UIColor darkTextColor];
            [cell.contentView addSubview:attentionLabel];
        }
        ExtensionInfo *extensionInfo = self.extensionArray[indexPath.row];
        UIImageView *iconImage = [cell.contentView viewWithTag:1000];
        [iconImage sd_setImageWithURL:[NSURL URLWithString:extensionInfo.pathUrl] placeholderImage:KRECOMMENDLISTDEFAULT];
        
        UILabel *nameLabel = [cell.contentView viewWithTag:1001];
        nameLabel.frame = CGRectMake(CGRectGetMaxX(iconImage.frame) + 5, CGRectGetMinY(iconImage.frame), kScreenW - CGRectGetMaxX(iconImage.frame) - 10, [Global getSizeOfString:extensionInfo.title maxWidth:kScreenW - CGRectGetMaxX(iconImage.frame) - 10 maxHeight:40 withFontSize:16.6].height);
        nameLabel.text = extensionInfo.title;
        
        UILabel *reportLabel = [cell.contentView viewWithTag:1002];
        reportLabel.frame = CGRectMake(CGRectGetMinX(nameLabel.frame), CGRectGetMaxY(iconImage.frame) - 15, CGRectGetWidth(nameLabel.frame) / 2, 15);
        reportLabel.text = [extensionInfo.source isEqualToString:@"1"]? @"与时校园":@"外网链接";
        
        UILabel *attentionLabel = [cell.contentView viewWithTag:1003];
        attentionLabel.frame = CGRectMake(CGRectGetMaxX(nameLabel.frame) - CGRectGetWidth(nameLabel.frame) / 2, CGRectGetMaxY(iconImage.frame) - 15, CGRectGetWidth(nameLabel.frame) / 2, 15);
        attentionLabel.text = [NSString stringWithFormat:@"%@阅读数",extensionInfo.readCount];
        return cell;
    }
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 3) {
        ExtensionInfo *extensionInfo = self.extensionArray[indexPath.row];
        WebViewController *webView = [[WebViewController alloc]initWithTitle:extensionInfo.title withRequest:[NSString stringWithFormat:@"%@/sys/home/gasStation?fileEntryId=%@",URL_BASE,extensionInfo.fileEntryId]];
        webView.enterWebViewBlock=^(){
            extensionInfo.readCount = [NSString stringWithFormat:@"%d",[extensionInfo.readCount intValue]+ 1];
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        };
        [self.navigationController pushViewController:webView animated:YES];
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return kScreenW / 2 ;
    }else if (indexPath.section == 1){
        return (kScreenW / 3 / 2 + 30) * 2 + 10;
    }else if (indexPath.section == 2){
        return 120;//img_pager
    }else{
        return 80;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (!section) {
        UIView *view = [[UIView alloc]init];
        view.frame = CGRectMake(0, 0, kScreenW, 10);
        return view;
    }
    NSArray *textArray = [NSArray arrayWithObjects:@"",@"",@"人气榜",@"推荐榜", nil];
    if ((section == 3) || ([[JHUserInfo getUserInfo].role_type isEqualToString:@"1"] && section == 2)) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 44)];
        view.backgroundColor = [UIColor whiteColor];
        [view addRoundedCorners:UIRectCornerTopLeft|UIRectCornerTopRight withRadii:CGSizeMake(10.0, 10.0)];
        
        UILabel *sepLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, 2, 20)];
        sepLabel.textColor = [UIColor blackColor];
        [view addSubview:sepLabel];
        
        UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 100, 30)];
        nameLabel.textAlignment = NSTextAlignmentLeft;
//        nameLabel.font = [UIFont systemFontOfSize:16];
        nameLabel.textColor = [UIColor blackColor];
        nameLabel.text = textArray[section];
        [view addSubview:nameLabel];
    
        CustomeButton *cusButton = [[CustomeButton alloc]initWithRelativeAlignment:KRelativeAlignmentLeft titleNormal:@"更多" imageNormal:@"More" frame:CGRectMake(kScreenW - 57, 12, 47, 20) titleRect:CGRectMake(0, 0, 35, 20) imageRect:CGRectMake(37, 0, 10, 20) textAlignment:NSTextAlignmentLeft font:[UIFont systemFontOfSize:16] titleColor:KTEXTMAINCOLOR];
        cusButton.tag = 9000+section;
        [cusButton addTarget:self action:@selector(moreList:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:cusButton];
        
        return view;
        
    }
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectZero;
    view.backgroundColor = KBACKGROUNDCOLOR;
    
    return view;
}
- (void)moreList:(UIButton *)sender{
    switch (sender.tag) {
        case 9002:{
            PopularityViewController *popularityVC = [[PopularityViewController alloc]init];
            popularityVC.titleStr = @"人气榜";
            popularityVC.titleArray = @[@"日榜",@"周榜",@"月榜"];
            popularityVC.vcStr = @"PopularityListViewController";
            [self.navigationController pushViewController:popularityVC animated:YES];
        }
            break;
        case 9003:{
            RecommendViewController *recommendVC = [[RecommendViewController alloc]init];
            [self.navigationController pushViewController:recommendVC animated:YES];
        }
            break;
        default:
            break;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (!section) {
        return 10.01f;
    }
    if ((section == 3) || ([[JHUserInfo getUserInfo].role_type isEqualToString:@"1"] && section == 2)) {
        return 44.01f;
    }
   
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    if (![[JHUserInfo getUserInfo].role_type isEqualToString:@"1"] && section == 2) {
        view.frame = CGRectZero;
        return view;
    }
    view.frame = CGRectMake(0, 0, kScreenW, 10);
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (![[JHUserInfo getUserInfo].role_type isEqualToString:@"1"] && section == 2) {
        return 0.01f;
    }
    return 10.01f;
}
#pragma mark - 进模块列表
- (void)enterCompany:(UIButton *)sender{
    MyLog(@"%ld",sender.tag);
    switch (sender.tag - 2000) {
        case 0:{    //心语互动
            if (strIsEmpty([Global getUserTokenInfo])) {
                [self login];
            }else{
                XinyuInteractionViewController *xinyuInteractionVC = [[XinyuInteractionViewController alloc]init];
                [self.navigationController pushViewController:xinyuInteractionVC animated:YES];
            }
        }
            break;
        case 1:{    //专业测评
            if (strIsEmpty([Global getUserTokenInfo])) {
                [self login];
            }else if ([[JHUserInfo getUserInfo].role_type isEqualToString:@"6"]) {
                [Global showActivityWithView:[[UIApplication sharedApplication] keyWindow] withText:@"该功能只针对与时老师和本校老师"];
            }else{
                MajorTestViewController *majorTestVC = [[MajorTestViewController alloc]init];
                [self.navigationController pushViewController:majorTestVC animated:YES];
//                YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
//                NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
//                [dic setValue:[Global getUserTokenInfo] forKey:@"token"]; //用户的token
//                [dic setValue:@"2" forKey:@"id"]; //首页专业测评
//                if ([[JHUserInfo getUserInfo].role_type isEqualToString:@"2"]||[[JHUserInfo getUserInfo].role_type isEqualToString:@"3"]||[[JHUserInfo getUserInfo].role_type isEqualToString:@"4"]) {
//                     [dic setValue:@"3" forKey:@"id"]; //3家长
//                }else if ([[JHUserInfo getUserInfo].role_type isEqualToString:@"5"]||[[JHUserInfo getUserInfo].role_type isEqualToString:@"7"]){
//
//                }else{
//                     [dic setValue:@"4" forKey:@"id"]; //4学生
//                }
//
//                [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppTeacherGetOutlinkById] andParmas:dic andComplition:^(id response, BOOL isuccess) {
//                    if (isuccess) {
//                        WebViewController *webView = [[WebViewController alloc]initWithTitle:@"专业测评" withRequest:response[@"content"]];
//                        [self.navigationController pushViewController:webView animated:YES];
//                    }
//                }];
//                WebViewController *webView = [[WebViewController alloc]initWithTitle:@"" withRequest:[NSString stringWithFormat:@"%@/interaction/renderCampu",URL_BASE]];
//                [self.navigationController pushViewController:webView animated:YES];
            }
        }
            break;
        case 2:{    //学业加油站
            if (strIsEmpty([Global getUserTokenInfo])) {
                [self login];
            }else{
                YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
                NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
                [dic setValue:[Global getUserTokenInfo] forKey:@"token"]; //用户的token
                [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppHomePageGetasStationSubject] andParmas:dic andComplition:^(id response, BOOL isuccess) {
                    if (isuccess) {
                        NSArray *array = [NSArray arrayWithArray:response];
                        NSMutableArray *titleArray = [[NSMutableArray alloc]init];
                        NSMutableArray *typeArray = [[NSMutableArray alloc]init];
                        [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                            [titleArray addObject:obj[@"subject_name"]];
                            [typeArray addObject:obj[@"subject_id"]];
                        }];
                        if (titleArray.count && typeArray.count) {
                            CouponViewController * couponVC = [[CouponViewController alloc]initWithTitleArray:titleArray couponTypeArray:typeArray VCStr:@"GasStationListViewController"];
                            [self.navigationController pushViewController:couponVC animated:YES];
                        }
                    }
                }];
            }
        }
            break;
        case 3:{    //放松区
            if (strIsEmpty([Global getUserTokenInfo])) {
                [self login];
            }else if ([[JHUserInfo getUserInfo].role_type isEqualToString:@"6"]) {
                [Global showActivityWithView:[[UIApplication sharedApplication] keyWindow] withText:@"该功能只针对与时老师和本校老师"];
            }else{
                RelaxViewController *relaxVC = [[RelaxViewController alloc]init];
                [self.navigationController pushViewController:relaxVC animated:YES];
            }
        }
            break;
        case 4:{    //趣味岛
            if (strIsEmpty([Global getUserTokenInfo])) {
               [self login];
            }else if ([[JHUserInfo getUserInfo].role_type isEqualToString:@"6"]) {
                [Global showActivityWithView:[[UIApplication sharedApplication] keyWindow] withText:@"该功能只针对与时老师和本校老师"];
            }else{
                InterestingIslandViewController *instIslandVC = [[InterestingIslandViewController alloc]init];
                [self.navigationController pushViewController:instIslandVC animated:YES];
            }
        }
            break;
        case 5:{    //与时名师
            YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
            NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
            [dic setValue:[Global getUserTokenInfo] forKey:@"token"]; //用户的token
            [dic setValue:@"1" forKey:@"id"]; //1与时名师
            [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppTeacherGetOutlinkById] andParmas:dic andComplition:^(id response, BOOL isuccess) {
                if (isuccess) {
                    WebViewController *webView = [[WebViewController alloc]initWithTitle:@"与时名师" withRequest:response[@"content"]];
                    [self.navigationController pushViewController:webView animated:YES];
                }
            }];
           
        }
            break;
        default:
            break;
    }
}

#pragma mark - 搜索
- (void)enterSearchView{
    YSSearchViewControllerViewController *searchViewController = [[YSSearchViewControllerViewController alloc]init];
    searchViewController.searchType = KSearchHomeType;
    [self.navigationController pushViewController:searchViewController animated:YES];
}

#pragma mark - 获取轮播图
- (void)getHomePage{
    YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
//    [dic setValue:@"1" forKey:@"page"];   //
//    [dic setValue:@"20" forKey:@"rows"]; //
    [dic setValue:@"4" forKey:@"businessType"];   //
    
    [yjNetWorkManger.requestSerializer setHTTPShouldHandleCookies:NO];
    [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppHomePageGetHomePage] andParmas:dic andComplition:^(id response, BOOL isuccess) {
        if (isuccess) {
            [self.imageDataArray removeAllObjects];
            NSMutableArray *array = [ExtensionInfo mj_objectArrayWithKeyValuesArray:response[@"list"]];
            [self.imageDataArray addObjectsFromArray:array];
            
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
            [self.tableView.mj_header endRefreshing];
        }
    }];
}
#pragma mark - 获取下面的推荐阅读列表
- (void)getHomeExtension{
    YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:@"1" forKey:@"page"];   //
    [dic setValue:@"3" forKey:@"rows"]; //
    [dic setValue:@"1" forKey:@"extension"];   //推荐阅读
   
    [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppHomePageGetHomePage] andParmas:dic andComplition:^(id response, BOOL isuccess) {
        if (isuccess) {
            NSArray *array = [NSArray arrayWithArray:response[@"list"]];
            if (array.count) {
                [self.extensionArray removeAllObjects];
                self.extensionArray =  [ExtensionInfo mj_objectArrayWithKeyValuesArray:response[@"list"]];
                [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:3] withRowAnimation:UITableViewRowAnimationNone];
                
            }
            [self.tableView.mj_header endRefreshing];
        }
    }];
}
#pragma mark - 通知
- (void)publish{
    if (strIsEmpty([Global getUserTokenInfo])) {
        [self login];
    }else{
        NewsViewController *newsVC = [[NewsViewController alloc]init];
        [self.navigationController pushViewController:newsVC animated:YES];
    }
}

#pragma mark - 获取人气榜数据
- (void)creatPopularityList{
    YJNetWorkManger *yjNetWorkManger =  [YJNetWorkManger shareManager];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:[Global getUserTokenInfo] forKey:@"token"]; //用户的token
    [yjNetWorkManger requestType:POST andURL:[JSPathUtil urlAppHomePageGetUserOrder] andParmas:dic andComplition:^(id response, BOOL isuccess) {
        if (isuccess) {
            NSMutableArray *array = [[NSMutableArray alloc]init];
           
            NSArray *dayList = [[NSArray alloc]initWithArray:response[@"dayList"]];
            if (dayList.count) {
                [array addObject:response[@"dayList"][0]];
            }
            NSArray *weekList = [[NSArray alloc]initWithArray:response[@"weekList"]];
            if (weekList.count) {
                [array addObject:response[@"weekList"][0]];
            }
            NSArray *monthList = [[NSArray alloc]initWithArray:response[@"monthList"]];
            if (monthList.count) {
                [array addObject:response[@"monthList"][0]];
            }
            
            self.popularityArray = [PopularityInfo mj_objectArrayWithKeyValuesArray:array];
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:2] withRowAnimation:UITableViewRowAnimationNone];
            [self.tableView.mj_header endRefreshing];
        }
    }];
}
- (void)enterImageView:(UIGestureRecognizer *)sender{
    ClassmateDetailViewController *classmateDetailVC = [[ClassmateDetailViewController alloc]init];
    classmateDetailVC.perentType = @"popularity";
    classmateDetailVC.popularityInfo = self.popularityArray[sender.view.tag - 5000];
    [self.navigationController pushViewController:classmateDetailVC animated:YES];
}
#pragma mark - 登录
- (void)login{
    YJLoginViewController *loginVC = [[YJLoginViewController alloc]initWithSelectIndex:0];
    loginVC.loginType = KLoginUser;
    [self.navigationController pushViewController:loginVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    MyLog(@"%f",scrollView.contentOffset.y);
//    CGFloat height=self.headimageview.height;
//    self.headimageview.y=-(height+ scrollView.contentOffset.y);
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
